package com.zhengx.moduletest.base;

import android.util.Log;


/**
 * name：BaseBusinessLazyFragment
 * class: 懒加载的Fragment
 * author: zhengx
 * create_time: 2019/1/23
 */

public abstract class BaseBusinessLazyFragment extends BaseBusinessFragment {

    private static final String TAG = "BaseBusinessLazyFragment";

    private boolean isDataLoaded;

    public abstract void doLazyBusiness();

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        Log.d(TAG, "setUserVisibleHint: " + isVisibleToUser);
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && mContentView != null && !isDataLoaded) {
            doLazyBusiness();
            isDataLoaded = true;
        }
    }

    @Override
    public void doBusiness() {
        if (getUserVisibleHint()) {
            doLazyBusiness();
            isDataLoaded = true;
        }
    }
}
